home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / libfpvm / WIN32 / Pvmfperror.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  1KB  |  52 lines

  1.  
  2. /* $Id: Pvmfperror.c,v 1.1 1997/06/27 16:29:08 pvmsrc Exp $ */
  3.  
  4. #include <stdio.h>
  5. #ifdef WIN32
  6. #include "..\..\include\pvm3.h"
  7. #include "..\..\src\pvmwin.h"
  8. #else 
  9. #include "pvm3.h"
  10. #endif
  11.  
  12. #include "pvm_consts.h"
  13.  
  14. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  15.  
  16. void /*__stdcall*/ __fortran
  17. PVMFPERROR (p_ptr,p_len, info)
  18. char * p_ptr; int p_len;
  19.    int *info;
  20. {
  21.    static char *buf = 0;
  22.    static int buflen = 0;
  23. #ifndef WIN32
  24.    char *malloc();
  25. #endif
  26.    /*
  27.     * Have to have a NUL at the end of the string, and
  28.     * the only way to do this portably is to copy the whole string
  29.     * into a malloc'ed buffer.  We keep the buffer around for
  30.     * future use rather than free'ing it each time we're done.
  31.     */
  32.    if (!buf)
  33.       buf = malloc(buflen = p_len + 1);
  34.    else
  35.       if (p_len + 1 > buflen) {
  36.          buflen = MAX(p_len + 1, buflen * 2);
  37.          /* don't use realloc; it might cause old data to be copied */
  38.          free(buf);
  39.          buf = malloc(buflen);
  40.       }
  41.    if (!buf) {
  42.       fprintf(stderr, "pvmfperror PvmNoMem");
  43.       *info = PvmNoMem;
  44.       return;
  45.    }
  46.    strncpy(buf, p_ptr, p_len);
  47.    buf[p_len] = '\0';
  48.  
  49.    *info = pvm_perror(buf);
  50. }
  51.  
  52.